<?php
class Champ{
  function __construct(){}
  
  static function getListeChamp($id){
    $output = array();
    $result = mysql_query("SELECT   id_champ AS id,
                    id_evenement AS id_evenement,
                    etiquette_champ AS etiquette, 
                    type_champ AS type, 
                    multiple_champ AS multiple,
                    selection_champ AS selection,
                    poids_champ AS poid
                  FROM ".BD_PREFIX."champ 
                  WHERE id_evenement = $id
                  ORDER BY poids_champ");
    echo mysql_error();
    while($data = mysql_fetch_array($result)){
      $output[] = $data; 
    }
    return $output; 
  }
  
  static function ajouterChamp($id_evenement,$etiquette,$type,$multiple,$selection,$poids){
  
    mysql_query("INSERT INTO ".BD_PREFIX."champ (  id_evenement,
                              etiquette_champ,
                              type_champ,
                              multiple_champ,
                              selection_champ,
                              poids_champ) 
                  VALUES(".clean_for_db($id_evenement).",".clean_for_db($etiquette).",".clean_for_db($type).",".clean_for_db($multiple).",".clean_for_db($selection).",".clean_for_db($poids).")");
    echo mysql_error();
    if (! $error = mysql_error())
      return mysql_insert_id();
    else
      echo $error;
      return false;
  }
  
  static function modifierChamp($id,$etiquette,$type,$multiple,$selection,$poids){

    mysql_query("UPDATE ".BD_PREFIX."champ
            SET etiquette_champ = ".clean_for_db($etiquette).",
              type_champ = ".clean_for_db($type).",
              selection_champ = ".clean_for_db($selection).",
              multiple_champ = ".clean_for_db($multiple).",
              poids_champ = ".clean_for_db($poids)."
            WHERE id_champ = ".clean_for_db($id));
    if (! $error = mysql_error())
      return $id;
    else
      echo $error;
      return false;
  }
  
  static function supprimerChamp($id){

    mysql_query("DELETE FROM ".BD_PREFIX."champ
            WHERE id_champ = ".clean_for_db($id)." LIMIT 1");
    if (! $error = mysql_error())
      return true;
    else{
      echo $error;
      return false;
    }
 }
  
  static function getChamp($id){
    $result = mysql_query("SELECT   id_champ AS id,
                    id_evenement AS id_evenement,
                    etiquette_champ AS etiquette, 
                    type_champ AS type, 
                    multiple_champ AS multiple,
                    selection_champ AS selection,
                    poids_champ AS poids
                  FROM ".BD_PREFIX."champ
                 WHERE id_champ = ".clean_for_db($id));
    echo mysql_error();
    return mysql_fetch_array($result);
  }
}
?>